package pentago.engine;

import java.awt.Point;
import java.util.Random;

public class RandomAlgorithm implements IPentagoAlgorithm {

    public Move getNextMove(byte[][] boardState, byte player, long maxRunTime) {
	Random random = new Random();
	Point marblePosition = new Point();
	byte direction, rotatedPlate;
	do {
	    marblePosition.x = random.nextInt(6);
	    marblePosition.y = random.nextInt(6);
	} while (boardState[marblePosition.x][marblePosition.y] != GameEngine.NO_PLAYER);

	if (random.nextInt(2) == Move.CLOCKWISE) {
	    direction = Move.CLOCKWISE;
	} else {
	    direction = Move.COUNTERCLOCKWISE;
	}

	try {
	    rotatedPlate = GameBoard.getInstance()
		    .getPlateFromMarbleTablePosition(marblePosition);
	    return new Move(marblePosition, rotatedPlate, direction);
	} catch (Exception e) {
	    e.printStackTrace();
	    return null;
	}

    }

    @Override
    public void executeTimeout() {
    }

}
